﻿@page "/admin/armanage"
@layout ImoviesBlazorAntPro.BasicLayout
@attribute [Authorize]
@*@attribute [Authorize(Roles = "admin")]*@
@*@attribute [Authorize(Roles = "guest")]*@

<PageContainer Title="年评管理">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>Admin</BreadcrumbItem>
            <BreadcrumbItem>年评管理</BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <ChildContent>
        <Card>
            <Table Loading="_loading" HidePagination="true" PageSize="@dataList.Count" TItem="AnnualReviewDto" DataSource="@dataList"
                @bind-SelectedRows="selectedRows" Size="TableSize.Small">
                <TitleTemplate>
                    <Space Size="@("20")">
                        <SpaceItem>
                            <div style="display: inline;">
                                <span>选择分类：</span>
                                <SimpleSelect Placeholder="选择视频分类" Style="width: unset;" @bind-Value="@_videoCate"
                                              OnSelectedItemChanged="VideoCateSelectedChangeAsync">
                                    <SelectOptions>
                                        <SimpleSelectOption Value="1" Label="电视剧"></SimpleSelectOption>
                                        <SimpleSelectOption Value="2" Label="电影"></SimpleSelectOption>
                                        <SimpleSelectOption Value="3" Label="动漫"></SimpleSelectOption>
                                    </SelectOptions>
                                </SimpleSelect>
                            </div>
                        </SpaceItem>
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Plus"
                                OnClick="ShowAddModal">添加评价</Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Button Danger Type="@ButtonType.Primary" Icon="@IconType.Outline.Delete"
                                OnClick="BatchDelete">批量删除</Button>
                        </SpaceItem>
                    </Space>
                </TitleTemplate>

                <ChildContent>
                    <Selection Key="@(context.Id.ToString())" />
                    <PropertyColumn Title="Id" Ellipsis Property="x=>x.Id" Sortable ShowSorterTooltip="false" />
                     <PropertyColumn Title="年份" Property="x=>x.Year" Sortable ShowSorterTooltip="false" />
                    <PropertyColumn Title="评语" Ellipsis Property="x=>x.Comment" />
                    <ActionColumn Title="操作" Align="@ColumnAlign.Center" Width="160">
                        <Space>
                            <SpaceItem>
                                <Button Type="primary" Size="small" OnClick="()=>ShowEditModal(context)"
                                    Style="margin-right: 10px;">编辑</Button>
                            </SpaceItem>
                            <SpaceItem>
                                <Popconfirm Title="确定删除吗?" OkText="确认" CancelText="取消"
                                    OnConfirm="()=>ConfirmDeleteAsync(context.Id)">
                                    <Button Danger Size="small">删除</Button>
                                </Popconfirm>
                            </SpaceItem>
                        </Space>
                    </ActionColumn>
                </ChildContent>
            </Table>

        </Card>
    </ChildContent>
</PageContainer>


<Modal Title="添加" Width="800" MaxBodyHeight="@("620px")" MaskClosable="@false" Visible="@_addModalVisible"
    OkText="@("提交")" CancelText="@("取消")" Centered="true" OnOk="@HandleAddModalOkAsync"
    OnCancel="@HandleAddModalCancel">
    <Form Model="@addModel" LabelColSpan="4" WrapperColSpan="20" OnFinish="OnAddFormFinish"
        OnFinishFailed="OnAddFormFinishFailed" @ref="@_addForm">
        <FormItem Label="年份">
             <AntDesign.InputNumber Style="width: 100%;" @bind-Value="@context.Year" />
        </FormItem>
        <FormItem Label="评语">
            <Input @bind-Value="@context.Comment" />
        </FormItem>
    </Form>
</Modal>


<Modal Title="编辑" Width="800" MaxBodyHeight="@("620px")" MaskClosable="@false" Visible="@_editModalVisible"
    OkText="@("提交")" CancelText="@("取消")" Centered="true" OnOk="@HandleEditModalOkAsync"
    OnCancel="@HandleEditModalCancel">
    <Form Model="@editModel" LabelColSpan="4" WrapperColSpan="20" OnFinish="OnEditFormFinish"
        OnFinishFailed="OnEditFormFinishFailed" @ref="@_editForm">
        <FormItem Label="年份">
             <AntDesign.InputNumber Style="width: 100%;" @bind-Value="@context.Year" />
        </FormItem>
        <FormItem Label="评语">
            <Input @bind-Value="@context.Comment" />
        </FormItem>
    </Form>
</Modal>